package teaching.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import teaching.pojo.Post;

import java.util.List;

/**
 * Author:20201002983_郑雨蓓
 * Date: 2024/4/15
 * Description:
 */
public interface PostMapper {
    //    @Select("select * from post")
//    List<Post> getAll();
    @Select("SELECT p.*, t.name AS tagName, s.avatar AS studentAvatar " +
            "FROM post p " +
            "LEFT JOIN tag t ON p.tag_id = t.id " +
            "LEFT JOIN student s ON p.student_userName = s.username " +
            "ORDER BY p.id DESC")
    List<Post> getAll();

    @Insert("INSERT INTO post(title, content, create_time, student_userName, tag_id) " +
            "VALUES(#{post.title}, #{post.content}, #{post.createTime}, #{post.studentUserName}, #{post.tagId})")
    int insertPost(@Param("post") Post post);

}
